/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.can.bc;

import edu.upn.sigemfi.can.be.TransaccionGiroWeb;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Programador
 */
public class TransaccionGiroWebDelegate {

    private TransaccionGiroWebFacadeLocal local;

    public TransaccionGiroWebDelegate(){
        local = lookupTransaccionGiroWebFacade();
    }

     public void crear(TransaccionGiroWeb transaccionGiroWeb) throws Exception{
        try {
            local.create(transaccionGiroWeb);
        } catch (Exception e) {
            local=lookupTransaccionGiroWebFacade();
            throw new Exception("Crear Transaccion Giro Web" + e.getMessage(), e);
        }
    }

    public void editar(TransaccionGiroWeb transaccionGiroWeb) throws Exception{
        try {
            local.edit(transaccionGiroWeb);
        } catch (Exception e) {
            local=lookupTransaccionGiroWebFacade();
            throw new Exception("Editar Transaccion Giro Web" + e.getMessage(), e);
        }
    }

    public void eliminar(TransaccionGiroWeb transaccionGiroWeb) throws Exception{
        try {
            local.remove(transaccionGiroWeb);
        } catch (Exception e) {
            local=lookupTransaccionGiroWebFacade();
            throw new Exception("Eliminar Transaccion Giro Web" + e.getMessage(), e);
        }
    }

    public TransaccionGiroWeb buscar(long codigo) throws Exception{
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local=lookupTransaccionGiroWebFacade();
            throw new Exception("Buscar Transaccion Giro Web" + e.getMessage(), e);
        }
    }

    public List<TransaccionGiroWeb> listar() throws Exception {
        try {
            return local.findAll();
        } catch (Exception e) {
            local = lookupTransaccionGiroWebFacade();
            throw new Exception("Listar Transaccion Giro Web. " + e.getMessage(), e);
        }
    }

    private TransaccionGiroWebFacadeLocal lookupTransaccionGiroWebFacade() {
        try {
            Context c = new InitialContext();
            return (TransaccionGiroWebFacadeLocal) c.lookup("java:comp/env/TransaccionGiroWebFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }





}
